import foldWrap from "../commonComponents/fold.vue"
import templateItems from "../commonComponents/templateItems.vue"
import useInfo from "../progressPublic/useInfo.vue"

export default {
  data() {
    return {
      bodyShow: false,
      countShow: false,
      id: false,
      dailyDetail: [
        {
          title: '基本信息',
          list: [
            {
              element: "read",
              singLine: 1,
              isRequired: false,
              key: "releaseUnit",
              attributesValue: "",
              label: "发布单位",
            },
            {
              element: "read",
              isRequired: false,
              singLine: 1,
              attributesValue: "",
              key: "createTime",
              label: "创建时间",
            },
            {
              element: "read",
              isRequired: false,
              singLine: 1,
              attributesValue: "",
              key: "releaseMan",
              label: "发布人",
            },
            {
              element: "read",
              isRequired: false,
              singLine: 1,
              attributesValue: "",
              key: "timeArea",
              label: "报告周期",
            },
            {
              element: "read",
              isRequired: false,
              attributesValue: "",
              singLine: 1,
              key: "dailyEndedTime",
              label: "反馈截止时间",
            },
          ],
        }
      ],
      submitList: [
        {
          title: '情况反馈',
          list: [
            {
              element: "radio",
              singLine: 1,
              layer: 1,
              isRequired: true,
              isReadonly: false,
              id: "systemSituation",
              attributesValue: "",
              label: "系统运行情况",
              options: [
                {text: "正常", value: "正常"},
                {text: "异常", value: "异常"},
              ]
            },
            {
              element: "text",
              isRequired: true,
              singLine: 1,
              isReadonly: false,
              attributesValue: "",
              id: "attackNumber",
              label: "受攻击次数",
            },
            {
              element: "text",
              isRequired: true,
              isReadonly: false,
              singLine: 1,
              attributesValue: "",
              id: "eventNumber",
              label: "发生事件数",
            },
            {
              element: "textarea",
              isRequired: false,
              isReadonly: false,
              attributesValue: "",
              id: "situationDesc",
              label: "情况描述",
            },
          ],
        }
      ],
      detail: false,
      feedBackList: [],
      unFeedBackList: [],
    }
  },
  methods: {
    init() {
      this.lastTitle = this.$store.state.showFlag;
      this.headerRightType = this.$store.state.headerRightType;
      this.bodyShow = false;
      _methods.headerTitleChange(70);
      this.id = _methods.getUrlParam("id");
      // let listType = _methods.getUrlParam("listType");
      // this.dPath = {
      //   1: "/dailyReportList",
      //   2: "/workReport"
      // }[listType];
      _data.userInfo.isCenterInit(() => {
        this.getFeedBackList(0);
        this.getFeedBackList(1);
        this.countShow = true;
        this.getDetail();
      }, () => {
        this.getSubDetail();
      });
    },
    getDetail() {
      let data = {
        id: this.id,
      };
      _ajax.noLoading(_ajaxUrls.dailyReportDetail.url,
        data,
        (ajData) => {
          let vl = ajData.result;
          this.detail = vl;
          vl.timeArea = vl.cycleStartTime + " 至 " + vl.cycleEndTime;
          let dd = this.dailyDetail[0].list;
          dd.forEach(i => {
            let kv = vl[i.key];
            if (kv) {
              i.attributesValue = kv;
            }
          });
          this.bodyShow = true;
        },
        _ajaxUrls.dailyReportDetail.type);
    },
    getSubDetail() {
      let data = {
        fId: this.id,
      };
      _ajax.noLoading(_ajaxUrls.dailyReportDetailSub.url,
        data,
        (ajData) => {
          let vl = ajData.result.dailyReport;
          let vl2 = ajData.result;
          this.detail = vl2;
          let dd = [
            {
              element: "read",
              singLine: 1,
              isRequired: false,
              key: "releaseUnit",
              attributesValue: "",
              label: "发布单位",
            },
            {
              element: "read",
              isRequired: false,
              singLine: 1,
              attributesValue: "",
              key: "createTime",
              label: "创建时间",
            },
            {
              element: "read",
              isRequired: false,
              singLine: 1,
              attributesValue: "",
              key: "releaseMan",
              label: "发布人",
            },
            {
              element: "read",
              isRequired: false,
              attributesValue: "",
              singLine: 1,
              key: "dailyEndedTime",
              label: "反馈截止时间",
            },
            {
              element: "read",
              isRequired: false,
              key: "requirement",
              attributesValue: "",
              label: "报告要求",
            }
          ];
          dd.forEach(i => {
            let kv = vl[i.key];
            if (kv) {
              i.attributesValue = kv;
            }
          });
          this.dailyDetail[0].list = dd;
          if (vl2.isSubmit == 1) {
            this.submitList[0].list = this.submitList[0].list.map(i => {
              i.isReadonly = true;
              i.element = "read";
              i.isRequired = false;
              if (i.id == "attackNumber" || i.id == "eventNumber"){
                i.attributesValue = vl2[i.id] + "次";
              }else {
                i.attributesValue = vl2[i.id]
              }
              return i;
            });
          }
          this.bodyShow = true;
        },
        _ajaxUrls.dailyReportDetailSub.type);
    },
    getFeedBackList(isSubmit = 0) {
      //isSubmit 0 未反馈 1已反馈
      let data = {
        page: 1,
        size: 1000,
        reportID: this.id,
        isSubmit: isSubmit,
      };
      let key = {
        0: "unFeedBackList",
        1: "feedBackList"
      }[isSubmit];
      _ajax.noLoading(_ajaxUrls.dailyReportSummary.url,
        data,
        (ajData) => {
          this[key] = ajData.result.records;
        }, _ajaxUrls.dailyReportSummary.type);
    },
    goFeedBackDetail(item) {

      let val = item.content;

      let valArr = val.split("$$");

      valArr.forEach((i) => {

        let vi = i.split("=");

        let key = vi[0];

        _data.dailyDetail.configList[key].value = vi[1];

      });

      _data.dailyDetail.checkedItem = item;

      _methods.goPath(this.dPath + "/drDetail/drFeedBackDetail");

    },
    submit(){
      let data = {
        writerID: _data.userInfo.userId,
        id: this.id,
        isSubmit: 1,
      };
      let flag = _methods.checkRequired(this.submitList, 0);
      if (flag) {
        this.submitList[0].list.forEach(i => {
          data[i.id] = i.attributesValue;
        });
        _ajax.confirmWithLoading(_ajaxUrls.dailyReportSubmit.url,
          data,
          () => {
            _alert.alert(() => {
              _vrvInit.isPushCloseWindow();
              _methods.meScrollTriggerDownScrollArr([_data.dailyPendingList, _data.dailyCompleteList]);
              _methods.goBack();
            });
          },
          _ajaxUrls.bulletinApproval.type,
          "是否确认提交?");
      }
    },
  },
  mounted() {
    window._vrvInit.isPush().then(() => {
      this.init();
    });
  },
  beforeDestroy() {
    _methods.headerTitleChange(this.lastTitle, true);
    _methods.headerRightShow(this.headerRightType);
  },
  components: {
    foldWrap,
    templateItems,
    useInfo,
  },
}
